package com.input4hua.expr.time;


import com.input4hua.expr.time.handler.day.DayExprHandler;
import com.input4hua.expr.time.handler.day.ShortDayExprHandler;
import com.input4hua.expr.time.handler.DayHourExprHandler;
import com.input4hua.expr.time.handler.hour.ShortHourExprHandler;

/**
 * 时间表达式转换 处理链客户端
 * @author Jiahua.hu
 * @since 13 May 2019
 */
public class DateHandlerClientSingleton implements DateHandler {

	private static final DateHandlerClientSingleton instance = new DateHandlerClientSingleton();

	private AbstractDateHandler top;

	private DateHandlerClientSingleton() {
		//组织责任链
		ShortDayExprHandler topHandler = new ShortDayExprHandler();
		DayExprHandler dayExprHandler = new DayExprHandler();
		ShortHourExprHandler shothourExprHandler = new ShortHourExprHandler();
		DayHourExprHandler dayHourExprHandler = new DayHourExprHandler();

		topHandler.setNextHandler(dayExprHandler);
		dayExprHandler.setNextHandler(shothourExprHandler);
		shothourExprHandler.setNextHandler(dayHourExprHandler);

		this.top = topHandler;
	}

	public static DateHandlerClientSingleton getInstance() {
		return instance;
	}

	@Override
	public String process(String req) {
		return top.process(req);
	}
}
